<?php

namespace app\api\controller;

use app\api\model\ForumEssayModel;
use app\BaseController;

class ForumEssay extends BaseController
{
    public function index()
    {
        //接收id
        $type_id = $this->request->get('type_id');
        if (empty($type_id)) {
            $this->error('参数错误');
        }
//        halt($type_id);
        $model = new ForumEssayModel();
        $data = $model->where(['status'=>1,'type_id'=>$type_id])
            ->with('typeId')
            ->withoutField('updatetime,status')
            ->select()->toArray();
        if (empty($data)) {
            $this->error('暂无数据');
        }
        //json转数组
        foreach ($data as $key => $value) {
            $data[$key]['imageurls'] = json_decode($data[$key]['imageurls'], true);
            $data[$key]['type'] = json_decode($data[$key]['type'], true);
        }
        $this->success('成功',$data);
    }

}